import http from '@/utils/http'

// 【获取】文章列表
async function getArticleRequest() {
  return await http({
    url: '/posts',
    method: 'get'
  })
}

interface i_article_data {
  id?: number
  title: string
  content: string
  status: boolean
}

// 【发布】文章
async function addArticleRequest(value: i_article_data) {
  const { title, content, status } = value
  return await http({
    url: '/posts',
    method: 'post',
    data: {
      title,
      content,
      status
    }
  })
}

// 【修改】文章
async function updateArticleRequest(value: i_article_data) {
  const { title, content, status, id } = value
  return await http({
    url: `/posts/` + id,
    method: 'patch',
    data: {
      title,
      content,
      status
    }
  })
}

// 【删除】文章
async function delArticleRequest(id: any) {
  return await http({
    url: `/posts/${id}`,
    method: 'delete'
  })
}

export { getArticleRequest, addArticleRequest, updateArticleRequest, delArticleRequest }
